/**********************************************************************
File Name   : UPI_OS_private.h

Description : UPI OS Interface Private header file 
				Implemetion on Linux

Copyright (C) 2008 SMiT

Name			Version			Date			Modification
----------		-------			----------		-------------
Zhao Liang		V0.1			2008.04.08		Create
Zhao Liang		V0.3			2008.04.16		Alpha Test
**********************************************************************/

#ifndef _UPI_OS_PRIVATE_H
#define _UPI_OS_PRIVATE_H

/**********************************************************************
	Includes
**********************************************************************/
#include "UPI.h" 

#ifdef  __cplusplus
extern "C" {
#endif


/**********************************************************************
	Constance
**********************************************************************/
#define C_UPI_OS_VERSION							("UPI_OS implemetion on Linux.")
#define C_UPI_OS_QUEUE_SIGNATURE					(0x12345678)
#define C_UPI_OS_QUEUE_CLEARED						(0x87654321)

/* Timer Configuration */
#define C_UPI_OS_TIMER_POLL_INTERVAL				(1000)	

#define C_UPI_OS_TIMER_POLL_THREAD_STACK_SIZE		(C_UPI_OS_DEFAULT_STACKSIZE)				
#define C_UPI_OS_TIMER_POLL_THREAD_PRIORITY			(40)
#define C_UPI_OS_TIMER_POLL_THREAD_NAME				("PollTimerThread")

#define C_UPI_OS_TIMER_TRIGGER_THREAD_STACK_SIZE	(C_UPI_OS_DEFAULT_STACKSIZE*2)				
#define C_UPI_OS_TIMER_TRIGGER_THREAD_PRIORITY		(40)
#define C_UPI_OS_TIMER_TRIGGER_THREAD_NAME			("TriggerTimerThread")

#define C_UPI_OS_FATAL_ERROR_MSG					"FATAL ERROR\n"
#define C_UPI_OS_CRITICAL_ERROR_MSG					"CRITICAL ERROR\n"
#define C_UPI_OS_UNKNOWN_ERROR_MSG					"UNKNOWN ERROR\n"

typedef enum
{
	C_UPI_OS_TIMER_NOT_USED = 0,
	C_UPI_OS_TIMER_STOP,
	C_UPI_OS_TIMER_RUN	
}UPI_OsTimerStatus;

/**********************************************************************
	Types
**********************************************************************/
typedef struct _UPI_OsQueueInfo
{
	UPI_int32		Sig;
	UPI_uint32		MaxMessage;
	UPI_uint32		MaxMessageSize;
	UPI_uint32		MessageCount;
	UPI_uint32		Index;
	UPI_OsSemHandle	ProtectSema;
	UPI_OsSemHandle	SyncSema;
	UPI_int8		*pMsgPool;
}UPI_OsQueueInfo, *pUPI_OsQueueInfo;

typedef struct _UPI_OsTimerInfo
{
	UPI_OsTimerStatus	Status;
	void (*pTimerFunc)(void*);
	void				*pArg;
	UPI_OsSysTime		InitValue;
	UPI_OsSysTime		Modulus;
	UPI_OsSysTime		NextTrigger;
}UPI_OsTimerInfo, *pUPI_OsTimerInfo;

typedef struct _UPI_OsTimerHeader
{
	UPI_int32			InitFlag;
	UPI_OsSemHandle		Sema;
	UPI_OsQueueHandle	Queue;
	UPI_OsThreadHandle	TimerPollThread;
	UPI_OsThreadHandle	TimerTriggerThread;
	pUPI_OsTimerInfo	pTimer;
}UPI_OsTimerHeader, *pUPI_OsTimerHeader;


typedef struct _UPI_OsTimerMsg
{
	void (*pTimerFunc)(void*);
	void	*pArg;
}UPI_OsTimerMsg, *pUPI_OsTimerMsg;

/**********************************************************************
	Functions
**********************************************************************/
void _UPI_os_free(void *pBuffer);

#ifdef  __cplusplus
}
#endif

#endif /* _UPI_OS_PRIVATE_H */

